package com.ma5d.driver.driver.controller;

import com.ma5d.driver.common.login.UserLogin;
import com.ma5d.driver.common.result.Result;
import com.ma5d.driver.common.util.AuthContextHolder;
import com.ma5d.driver.driver.service.DriverService;
import com.ma5d.driver.model.form.DriverFaceModelForm;
import com.ma5d.driver.model.form.UpdateDriverAuthInfoForm;
import com.ma5d.driver.model.vo.driver.DriverLoginVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/driver")
public class DriverController {

    @Resource
    private DriverService driverService;

    @GetMapping("/login/{code}")
    public Result<String> login(@PathVariable String code) {
        return Result.ok(driverService.login(code));
    }

    @UserLogin
    @GetMapping("/getDriverLoginInfo")
    public Result<DriverLoginVo> getDriverLoginInfo() {
        return Result.ok(driverService.getDriverLoginInfo());
    }

    @UserLogin
    @PostMapping("/updateDriverAuthInfo")
    public Result<Boolean> updateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm updateDriverAuthInfoForm) {
        return Result.ok(driverService.updateDriverAuthInfo(updateDriverAuthInfoForm));
    }

    @UserLogin
    @PostMapping("/createDriverFaceModel")
    public Result<Boolean> createDriverFaceModel(@RequestBody DriverFaceModelForm driverFaceModelForm){
        driverFaceModelForm.setDriverId(AuthContextHolder.getUserId());
        Boolean success = driverService.createDriverFaceModel(driverFaceModelForm);
        return Result.ok(success);
    }

}
